package com.zy.modules.sys.service.impl;

import com.zy.modules.sys.entity.SysLogEntity;
import com.zy.modules.sys.repo.LogRepository;
import com.zy.modules.sys.service.SysLogService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("sysLogService")
public class SysLogServiceImpl implements SysLogService {
    @Resource
    private LogRepository logRepository;

    @Override
    public SysLogEntity queryObject(Long id) {
        return logRepository.findOne(id);
    }

    @Override
    public List<SysLogEntity> queryList(Map<String, Object> map) {
        int limit = (int) map.getOrDefault("limit", 10);
        int offset = (int) map.getOrDefault("offset", 0);
        Pageable pageable = new PageRequest(offset, limit);
        Page<SysLogEntity> entities = logRepository.findAll(pageable);
        return entities.getContent();
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        long count = logRepository.count();
        return (int) count;
    }

    @Override
    public void save(SysLogEntity sysLog) {
        logRepository.save(sysLog);
    }

    @Override
    public void delete(Long id) {
        logRepository.delete(id);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            logRepository.delete(id);
        }
    }

}
